extends Node2D


var coin_node: PackedScene = preload("res://Game/Components/Coin/coin.tscn")
var coin_number: int = 0
const COIN_ADD_TIME: float = 0.5
const COIN_DISTANCE: int = 20

onready var add_coin_tween: Tween = get_node("AddCoinTween")

func _ready() -> void:
    pass

func _draw() -> void:
    if OS.is_debug_build():
        draw_rect(Rect2(0, -30, 200, 60), Color(1, 0, 0, 1), false)
    pass

func add_coin(n: int) -> void:
    var last_coin_number: int = coin_number
    coin_number = coin_number + n
    add_coin_tween.start()

    for i in range(n):
        var c: Node2D = coin_node.instance()
        c.position = Vector2(500, -200)
        c.scale = Vector2(6.0, 6.0)
        add_child(c)
        add_coin_tween.interpolate_property(
            c,
            "position",
            c.get_position(),
            Vector2((last_coin_number + i + 1) * COIN_DISTANCE, 0),
            COIN_ADD_TIME,
            Tween.TRANS_LINEAR,
            Tween.EASE_IN)
        add_coin_tween.interpolate_property(
            c,
            "scale",
            c.scale,
            Vector2(3.0, 3.0),
            COIN_ADD_TIME,
            Tween.TRANS_LINEAR,
            Tween.EASE_IN)
        yield(get_tree().create_timer(0.5), "timeout")

    pass

func pay_coin(n: int) -> bool:
    if n > coin_number or n < 0:
        return false
    return true
